import request from '@/router/axios';

// 查询商品分类列表
export function listCategory(query) {
  return request({
    url: '/shop-core/category/list',
    method: 'get',
    params: query,
  });
}

// 查询商品分类详细
export function getCategory(id) {
  return request({
    url: '/shop-core/category/' + id,
    method: 'get',
  });
}

// 新增商品分类
export function addCategory(data) {
  return request({
    url: '/shop-core/category',
    method: 'post',
    data: data,
  });
}

// 修改商品分类
export function updateCategory(data) {
  return request({
    url: '/shop-core/category',
    method: 'put',
    data: data,
  });
}

//获取分类列表数据
export function getCategoryTree(params) {
  return request({
    url: `/shop-core/category/list`,
    method: 'get',
    params,
  });
}

// 删除商品分类
export function delCategory(id) {
  return request({
    url: '/shop-core/category/' + id,
    method: 'delete',
  });
}

//获取所有可用品牌
export function getBrandListData() {
  return request({
    url: '/shop-core/brand/all',
    method: 'get',
  });
}
//获取所有可用分类
export function getCategoryListData() {
  return request({
    url: '/shop-core/category/all',
    method: 'get',
  });
}

//根据分类id获取关联品牌
export function getCategoryBrandListData(category_id) {
  return request({
    url: `/items/manager/category/brand/${category_id}`,
    method: 'get',
  });
}

// 获取所有可用规格
export function getSpecificationList() {
  return request({
    url: `/shop-core/spec/all`,
    method: 'get',
  });
}

//根据分类id获取关联规格
export const getCategorySpecListData = (category_id) => {
  return request({
    url: `/shop-core/category/spec/${category_id}`,
    method: 'get',
  });
};

// 禁用分类
export function disableCategory(id, type) {
  return request({
    url: `/shop-core/category/disable/${id}`,
    method: 'put',
    params: type,
  });
}

//保存获取关联规格
export function saveCategorySpec(category_id, params) {
  return request({
    url: `/shop-core/category/spec/${category_id}`,
    contentType: 'application/x-www-form-urlencoded',
    method: 'post',
    data: params,
  });
}

//保存获取关联品牌
export function saveCategoryBrand(category_id, data) {
  return request({
    url: `/items/manager/category/brand/${category_id}`,
    contentType: 'application/x-www-form-urlencoded',
    method: 'post',
    data: data,
  });
}
